-
Notifications
You must be signed in to change notification settings - Fork 13.5k
fresh binding should shadow the def in expand #143141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
tests/ui/resolve/fresh-should-shallow-definitation-after-macro-expand.rs
Outdated
Show resolved
Hide resolved
fn f() -> i8 { 42 } | ||
let f = || -> i16 { 42 }; | ||
|
||
let a: i16 = m!(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is breaking changes, should we run crate tests?
macro_rules! m {() => ( f() )} | ||
use m; | ||
let b: i16 = m!(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to test all permutations of
fn f
let f
macro_rules! m
use m
in all possible orders.
There should be 12 of them (the ones with use m
going before macro_rules! m
are impossible).
The testing statements let a/b/c/...
can then be inserted between all of them.
let a
fn f
let b
let f
let c
macro_rules! m
let d
use m
let e
Then we'll get exhaustive testing.
Upd: i8
-> FnF
, i16
-> LetF
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some more test cases:
{
m!(); // in a block before the import
}
macro_rules! m { ... }
use m;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a note, we should add additional test cases like without_decl_f
and without_closure_f
for better coverage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note on cases in f0
~f23
:
- For
let a: i8 = m!()
inf8~f23
, the macro expansion's f refers to function f. There are two distinct scenarios:- Using the declared function when found at macro definition site:
This behaves similarly to:fn f20() { macro_rules! m {() => ( f() )} // Only resolves to `fn f` at this position use m; fn f() -> i8 { 42 } let f = || -> i16 { 42 }; let a: i8 = m!(); }
fn f() { let x = 0; macro_rules! foo { () => { assert_eq!(x, 0); } } let x = 1; foo!(); }
- Using the declared function when the closure is unavailable:
fn b12() { let a: i8 = m!(); fn f() -> i8 { 42 } let f = || -> i16 { 42 }; macro_rules! m {() => ( f() )} // Although both exist, `let a` can only use `fn f` use m; }
- In other cases, it refers to the closure
f
.
I don't understand why this works and how it fixes the issue. |
Also "shallow" -> "shadow" in the PR/commit messages and file names. |
There may be a bug if
rust/compiler/rustc_resolve/src/ident.rs Lines 320 to 328 in 86e05cd
|
@rustbot ready |
Fixes #95237
r? @petrochenkov or @cjgillot